package com.lhh.company.website.config;

import com.lhh.company.website.entity.SysUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SysUserDetails implements UserDetails {


    private String id;

    private String username;

    private String password;

    private String status;

    private List<String> roles;


    public SysUserDetails(SysUser sysUser) {
        this.id = sysUser.getId();
        this.username = sysUser.getName();
        this.password = sysUser.getPasswd();
        this.status =  sysUser.getStatus();
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return List.of();
    }

    //    后面四个方法都是用户是否可用、是否过期之类的。我都设置为true
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
